package com.sto.stoapp.manager;

/**
 * 未发数据管理
 * 
 * @author hb
 * 
 */
public class UnSentDataManager {
	private static UnSentDataManager unSentDataManager;
	private int unSent = 0;
	
	private static final String UNDEND_SYNCH = "unsend_synch";
	
	public static UnSentDataManager getInstance() {
		synchronized (UNDEND_SYNCH) {
			if (unSentDataManager == null) {
				unSentDataManager = new UnSentDataManager();
			}
		return unSentDataManager;
		}
	}

	// 获取未发数据
	public int getUnSent() {
		synchronized (UNDEND_SYNCH) {
		return unSent;
		}
	}

	// 设置未发数据
	public void setUnSent(int unSent) {
		synchronized (UNDEND_SYNCH) {
			if(unSent >= 0){
				this.unSent = unSent;
			}else if(unSent < 0){
				this.unSent = 0;
			}
		}
	}
	/**
	 * 更新数据
	 * @param count
	 */
	private void updateSend(int count) {
		synchronized (UNDEND_SYNCH) {
			if(unSent >= count){
				unSent = getUnSent() - count;
			}else{
				unSent = 0;
			}
			
		}
	}
	
	/**
	 * 删除数据
	 */
	public void deleteCodeNumber(int count) {
		updateSend(count);
	}
	/**
	 * 增加一条
	 */
	public void addCodeNumber() {
		updateSend(-1);
	}

	/**
	 * 删除一票数据
	 */
	public void deleteCodeNumber() {
		updateSend(1);
	}
}
